<?php
class DarenModule
{
	public function index()
	{
		global $_FANWE;
		$sort = $_FANWE['request']['sort'];
		$page_args = array();
		
		switch($sort)
		{
			case 'new':
				$order = " ORDER BY photos DESC";
			break;
			default:
				$order = " ORDER BY photos DESC";
			break;
		}
		
		$daren_display = array();
		$photos = array();

		$sql = 'select a.*,b.user_name from '.FDB::table('user_count').' as a left join 
					'.FDB::table('user').' as b on a.uid=b.uid  '.$order.' LIMIT 40';
		$user_list =  FDB::fetchAll($sql);

		foreach( $user_list as $user ){
			$album_count = FDB::resultFirst('SELECT count(id) FROM '.FDB::table('album').' where uid='. $user['uid'] );
			$pics = FDB::fetchAll('SELECT * FROM '.FDB::table('share_photo').' where uid='. $user['uid'] . " order by photo_id desc limit 8");
			
			for($i=0; $i<8; $i++){
				if(empty($pics[$i]['share_id'])){
					$photos[$i] = array(
						'url' => "#",
						'img' => ""
					);
				}else{
					$photos[$i] = array(
						'url' => FU('note/index',array('sid'=>$pics[$i]['share_id'])),
						'img' => $pics[$i]['img']
					);
				}
			}
			
			$daren_display[$user['uid']] = array(
				"user" => $user,
				"albums" => $album_count,
				"pics" => $photos
			);
		}
		
		include template('page/daren/daren_index');
		display();
	}	
}
?>